package com.blunka.framework.client.ui.server;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import com.blunka.framework.client.constants.InitDesignConfig;
import com.blunka.framework.client.ui.MainFrame;

/**
 *
 *
 * @平台：统一开发平台
 * @文件名称：MainFrame.java
 * @文件描述：设计器主窗体界面
 * @author xuqiang
 * @日期：2018年5月25日下午2:56:44
 *
 */
public class MainFrameServer extends JDialog{

	public static MainFrameServer mainFrame = new MainFrameServer();

	private JSplitPane hSplitPane;

	public static MainFrameServer newInstance(){
		return mainFrame;
	}

	private MainFrameServer(){

		try {
			setTitle(InitDesignConfig.getDesignerName()+"-"+InitDesignConfig.getDesignerVersion()+"-服务端");
			Container container= getContentPane();
			container.setLayout(new BorderLayout());
			Toolkit kit = Toolkit.getDefaultToolkit(); //定义工具包
			int screenWidth = kit.getScreenSize().width/2 + 100; //获取屏幕的宽
			int screenHeight = kit.getScreenSize().height/2 + 100; //获取屏幕的高
			setSize(new Dimension(screenWidth, screenHeight));
			initFrame(container);
			//设置百分比例
			hSplitPane.setDividerLocation(kit.getScreenSize().width/6);
			setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			addWindowListener(new WindowAdapter() {
				public void windowClosing(WindowEvent e) {
					//不关闭，直接隐藏窗体
					mainFrame.setVisible(false);
					return;
				}
			});
			setModal(true);
			setLocationRelativeTo(MainFrame.getMainFrame());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private void initFrame(Container container){
		hSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

		hSplitPane.setRightComponent(MainPanelServer.newInstance());
		hSplitPane.setLeftComponent(new JScrollPane(TreeModelPanelServer.newInstance()));


		hSplitPane.setOneTouchExpandable(true);
		container.add(hSplitPane,BorderLayout.CENTER);

	}

}
